package com.rk.hosp.controller;

import com.rk.common.result.Result;
import com.rk.hosp.model.hosp.Hospital;
import com.rk.hosp.model.hosp.HospitalSet;
import com.rk.hosp.repository.HospitalRepository;
import com.rk.hosp.service.HospitalService;
import com.rk.hosp.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author :Rk.
 * @date : 2022/11/15
 */
@Slf4j
@RestController
@Api(tags = "医院管理接口")
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/list/{page}/{limit}")
    public Result index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                    HospitalQueryVo hospitalQueryVo) {
        try {
            Page<Hospital> hospitals = hospitalService.selectPage(page, limit, hospitalQueryVo);
        }catch (Exception e){
            return Result.fail("查询失败!");
        }
        return Result.ok(hospitalService.selectPage(page, limit, hospitalQueryVo));
    }


    @ApiOperation(value = "更新上线状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result lock(@PathVariable("id") String id,
                       @PathVariable("status")Integer status){
        try {
            hospitalService.updateStatus(id,status);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail();
        }
        return Result.ok();
    }


    @ApiOperation(value = "医院详情信息")
    @GetMapping("/showHospDetail/{id}")
    public Result showHospDetail(@PathVariable String id){
        Map<String, Object> map = hospitalService.getHospById(id);
        return Result.ok(map);
    }

}
